package com.qipay.baas.mapper;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.qipay.baas.model.OperateLog;

public class OperateLogSqlProvider {

    public String insertSelective(OperateLog record) {
        BEGIN();
        INSERT_INTO("operate_log");
        
        if (record.getUserId() != null) {
            VALUES("user_id", "#{userId,jdbcType=INTEGER}");
        }
        
        if (record.getService() != null) {
            VALUES("service", "#{service,jdbcType=VARCHAR}");
        }
        
        if (record.getIp() != null) {
            VALUES("ip", "#{ip,jdbcType=VARCHAR}");
        }
        
        if (record.getOperateDate() != null) {
            VALUES("operate_date", "#{operateDate,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUrl() != null) {
            VALUES("url", "#{url,jdbcType=VARCHAR}");
        }
        
        if (record.getMethod() != null) {
            VALUES("`method`", "#{method,jdbcType=VARCHAR}");
        }
        
        if (record.getParam() != null) {
            VALUES("param", "#{param,jdbcType=VARCHAR}");
        }
        
        if (record.getInfo() != null) {
            VALUES("info", "#{info,jdbcType=VARCHAR}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(OperateLog record) {
        BEGIN();
        UPDATE("operate_log");
        
        if (record.getUserId() != null) {
            SET("user_id = #{userId,jdbcType=INTEGER}");
        }
        
        if (record.getService() != null) {
            SET("service = #{service,jdbcType=VARCHAR}");
        }
        
        if (record.getIp() != null) {
            SET("ip = #{ip,jdbcType=VARCHAR}");
        }
        
        if (record.getOperateDate() != null) {
            SET("operate_date = #{operateDate,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUrl() != null) {
            SET("url = #{url,jdbcType=VARCHAR}");
        }
        
        if (record.getMethod() != null) {
            SET("`method` = #{method,jdbcType=VARCHAR}");
        }
        
        if (record.getParam() != null) {
            SET("param = #{param,jdbcType=VARCHAR}");
        }
        
        if (record.getInfo() != null) {
            SET("info = #{info,jdbcType=VARCHAR}");
        }
        
        WHERE("id = #{id,jdbcType=INTEGER}");
        
        return SQL();
    }
}